package com.lostandfound.service.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lostandfound.dao.UserDao;
import com.lostandfound.entity.User;
import com.lostandfound.service.TopicService;
import com.lostandfound.service.UserService;

@Service
@Transactional
public class UserServiceImpl implements UserService{
	
	@Autowired
    private UserDao userDaoImpl;
	@Autowired
	private TopicService topicService; 

	@Override
	public Serializable save(User obj) {
		
		return userDaoImpl.save(obj);
	}

	@Override
	public void update(User obj) {
		
		userDaoImpl.update(obj);
	}

	@Override
	public void delete(User obj) {
		
		userDaoImpl.delete(obj);
	}

	@Override
	public User selectByPrimary(Long id) {
		User user = userDaoImpl.selectByPrimary(id);
		return user;
	}

	@Override
	public User selectByUserCode(String userCode) {
		
		return userDaoImpl.selectByUserCode(userCode);
	}

	@SuppressWarnings("rawtypes")
	@Override
	public List listUserByPage(Map<String, Object> pagemap) {
		return userDaoImpl.listUserByPage(pagemap);
	}

	@Override
	public int Count(Map<String, Object> pagemap) {
		return userDaoImpl.Count(pagemap);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void deleteUserByBranch(Long[] uids) {

		for (Long long1 : uids) {
			topicService.deleteTopicByUser(long1);//先删除用户下的主贴
		}
		userDaoImpl.deleteUserByBranch(uids);//再执行删除用户
	}

}
